<?php 
include('../conn.php');

if(empty($_GET['shopid'])){
	$result_data_array['code'] = -100;
	$result_data_array['msg'] = '商家信息错误';
	echo json_encode($result_data_array);
	exit;
}

$result_data_array = array();

$page = 0;
$pagesize = 10;
$startDate = '';
$endDate = '';
$is_blance = 0;
$shopid = $_GET['shopid'];

if(isset($_GET['page'])){
	$page = $_GET['page'];
}


if(isset($_GET['pagesize'])){
	$pagesize = $_GET['pagesize'];
}

if(isset($_GET['is_blance']) && $_GET['is_blance'] == 1){
	$is_blance = $_GET['is_blance'];
}

if(isset($_GET['startDate'])){
	$startDate = $_GET['startDate'];
}

if(isset($_GET['endDate'])){
	$endDate = $_GET['endDate'];
}

$shop_sql = 'select rates from shop where shopid = '.$shopid;
$shop_query = mysql_query($shop_sql);
//商家数据
$shop_array = mysql_fetch_assoc($shop_query);

if(!$shop_array){
	$result_data_array['code'] = -100;
	$result_data_array['msg'] = '商家信息错误';
	echo json_encode($result_data_array);
	exit;

}

//返佣比率  %
if($shop_array['rates'] == null){
	$shop_array['rates'] = 0;
}
$shop_array['rates']+=0;
$rates = $shop_array['rates'];

$sum_sql = 'SELECT ROUND(SUM(totalprice),2) AS total_order_price,'
.'COUNT(*) AS total_order ,'
.'ROUND(SUM(blance_price),2) AS total_ying_jie_price ,'
.'ROUND(SUM(coupon_price),2) AS total_coupon_price ,'
.'ROUND(SUM(return_volume_price),2) AS total_return_volume_price,'
.'ROUND(SUM(distribution_fee),2)  AS total_distribution_fee,'
.'ROUND(SUM(fan_juan_price),2) AS total_fan_juan_price,'
.'ROUND(SUM(fan_yong_price),2) AS total_fan_yong_price '
.'FROM goodsorders WHERE shopid = '.$shopid.' and state > 0 and state != 4 and state != 6 and blance_state = '.$is_blance;

$order_sql = 'select numbers,totalprice,fan_yong_bi_li as fan_yong_bi_lv,fan_juan_bi_li as fan_juan_bi_lv,fan_yong_price,distribution_fee,return_volume_price,fan_juan_price,coupon_price,fu_kuan_datetime,balance_time,blance_price as ying_jie_price from goodsorders  where shopid = '.$shopid.' and state > 0 and state != 4 and state != 6 and blance_state = '.$is_blance;
if($endDate != '' && $startDate != ''){
	$order_sql.= ' and  fu_kuan_datetime >= "'.$startDate.'" and fu_kuan_datetime <= "'.$endDate.'"';
	$sum_sql.= ' and  fu_kuan_datetime >= "'.$startDate.'" and fu_kuan_datetime <= "'.$endDate.'"';
}
$order_sql.= ' order by ordersid desc';
$sum_query = mysql_query($sum_sql);
$sum_result = mysql_fetch_assoc($sum_query);
if(!$sum_result){
	$result_data_array['code'] = -100;
	$result_data_array['msg'] = '数据异常';
	echo json_encode($result_data_array);
	exit;

}
$order_data_array = array();
$order_sql.=' limit '.($page*$pagesize).', '.$pagesize;
$order_query = mysql_query($order_sql);
while ($row = mysql_fetch_assoc($order_query)) {
	$order_data_array[] = $row;
}

$result_data_array['code'] = 200;
$result_data_array['msg'] = '获取成果';
$result_data_array['total_data'] = $sum_result;
$result_data_array['data'] = $order_data_array;
echo json_encode($result_data_array);





 ?>